package com.cqan.entity;

import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.cqan.entity.pk.LongEntity;

@Entity
// 表名与类名不相同时重新定义表名.
@Table(name = "TBL_ATOM")
// 默认的缓存策略.
@SuppressWarnings("serial")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Atom extends LongEntity {

	private Map<AtomField, AtomValue> rows;
	
	private Report report;
	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "RID")
	public Report getReport() {
		return report;
	}
	
	@OneToMany(mappedBy="atom")
	@MapKey(name="field")
	public Map<AtomField, AtomValue> getRows() {
		return rows;
	}



	public void setRows(Map<AtomField, AtomValue> rows) {
		this.rows = rows;
	}



	public void setReport(Report report) {
		this.report = report;
	}


	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
